package com.qing.expert.modules.expert.controller;

import com.qing.expert.common.annotation.OperationLog;
import com.qing.expert.common.response.R;
import com.qing.expert.modules.expert.service.ExpertApplyService;
import com.qing.expert.modules.expert.vo.request.ExpertApplyRequest;
import com.qing.expert.modules.expert.vo.response.ExpertApplyStatusVO;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/expert/apply")
public class ExpertApplyController {

    @Resource
    private ExpertApplyService expertApplyService;

    /**
     * 提交达人申请
     */
    @OperationLog(action = "submit_expert_apply", detail = "提交达人申请")
    @PostMapping
    public R<Void> submitApply(
            @Validated @RequestBody ExpertApplyRequest request,
            HttpServletRequest httpRequest) {
        String userId = (String) httpRequest.getAttribute("userId");
        expertApplyService.submitApply(userId, request);
        return R.ok();
    }

    /**
     * 获取申请状态
     */
    @GetMapping("/status")
    public R<ExpertApplyStatusVO> getApplyStatus(HttpServletRequest request) {
        String userId = (String) request.getAttribute("userId");
        return R.ok(expertApplyService.getApplyStatus(userId));
    }
}